#include <iostream>

using namespace std;
int ts[13]={0,31,0,31,30,31,30,31,31,30,31,30,31,};
int main(){
    int n,y;
    while (cin>>n>>y){
        if (y==2){
            if (n%4==0&&n%100!=0||n%400==0){
                cout<<29<<endl;
            } else{
                cout<<28<<endl;
            }
        } else{
            cout<<ts[y]<<endl;
        }

    }
    return 0;
}